<!--
 * @FilePath     : /study_code/layui/12-6-1.html
 * @Description  : api from.render()
 * @Date         : 2025-04-07 16:07:21
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-07 16:26:10
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
  </head>
  <body>
    <hr />

    <button id="btn1">动态加载表单内容</button>
    <button id="btn2">渲染所有表单</button>
    <button id="btn3">只渲染下拉</button>
    <button id="btn4">只渲染复选框</button>

    <hr />
    <div id="formContainer" class="layui-form">
      <p>这里放置表单</p>
    </div>
    <hr />

    <script src="/layui/dist/layui.js"></script>
    <script>
      function clickHandler1() {}

      layui.use(['form', 'jquery'], function () {
        var form = layui.form,
          $ = layui.$

        $('#btn1').on('click', function () {
          var html =
            '<div class="layui-form-item">' +
            '  <label class="layui-form-label">默认</label>' +
            '  <div class="layui-input-block">' +
            '    <select name="interest" lay-filter="aihao">' +
            '      <option value=""></option>' +
            '      <option value="0">写作</option>' +
            '      <option value="1" selected>阅读</option>' +
            '      <option value="2">游戏</option>' +
            '      <option value="3">音乐</option>' +
            '      <option value="4">旅行</option>' +
            '    </select>' +
            '  </div>' +
            '</div>' +
            '<div class="layui-form-item">' +
            '  <label class="layui-form-label">复选框</label>' +
            '  <div class="layui-input-block">' +
            '    <input type="checkbox" name="arr[0]" title="选项1" />' +
            '    <input type="checkbox" name="arr[1]" title="选项2" checked />' +
            '    <input type="checkbox" name="arr[2]" title="选项3" />' +
            '  </div>' +
            '</div>'
          $('#formContainer').append(html)
        })

        $('#btn2').on('click', function () {
          form.render()
        })

        $('#btn3').on('click', function () {
          form.render('select')
        })

        $('#btn4').on('click', function () {
          form.render('checkbox')
        })
      })
    </script>
  </body>
</html>
